using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Decav.Gatsb.Configuration
{
    /// <summary>
    /// Provides application specific configuration variables.
    /// </summary>
    public class GatsbConfigurationSection : ConfigurationSection
    {
        /// <summary>
        /// Gets the configuration section.
        /// </summary>
        public static GatsbConfigurationSection Current
        {
            get
            {
                return (GatsbConfigurationSection)ConfigurationManager.GetSection("decav.gatsb");
            }
        }

        /// <summary>
        /// Gets the name of the <see cref="IGeocoder"/> that is used in this application instance.
        /// </summary>
        [ConfigurationProperty("geocoderTypeName", IsRequired = true)]
        public string GeocoderTypeName
        {
            get
            {
                return (string)this["geocoderTypeName"];
            }
        }

        /// <summary>
        /// Gets the path to the error log.
        /// </summary>
        [ConfigurationProperty("errorLogPath", IsRequired=true)]
        public string ErrorLogPath
        {
            get
            {
                return (string)this["errorLogPath"];
            }
        }

        /// <summary>
        /// Gets the location where users have uploaded images that have been resized and cached.
        /// </summary>
        [ConfigurationProperty("cachedUserUploadedImagesFolder", IsRequired = true)]
        public string CachedUserUploadedImagesFolder
        {
            get
            {
                return (string)this["cachedUserUploadedImagesFolder"];
            }
        }

        /// <summary>
        /// Gets the location where users have uploaded and defined images.
        /// </summary>
        [ConfigurationProperty("userUploadedImagesFolder", IsRequired = true)]
        public string UserUploadedImagesFolder
        {
            get
            {
                return (string)this["userUploadedImagesFolder"];
            }
        }

        /// <summary>
        /// Gets the number of days to go back that constitutes "recent".
        /// </summary>
        [ConfigurationProperty("recentWithinDays", IsRequired=true)]
        public int RecentWithinDays
        {
            get
            {
                return (int)this["recentWithinDays"];
            }
        }

        [ConfigurationProperty("mobileProviders")]
        [ConfigurationCollection(typeof(MobileProviderConfigurationCollection))]
        public MobileProviderConfigurationCollection MobileProviders
        {
            get
            {
                return (MobileProviderConfigurationCollection)this["mobileProviders"];
            }
        }

        /// <summary>
        /// Gets the email address that notifications appear to originate from.
        /// </summary>
        [ConfigurationProperty("notificationFromAddress",
                          DefaultValue="notification@gatsb.com",
                          IsRequired = true)]
        public string NotificationFromAddress
        {
            get
            {
                return (string)this["notificationFromAddress"];
            }
        }

        /// <summary>
        /// Gets the default page an authenticated user is sent to as a landing page.
        /// </summary>
        [ConfigurationProperty("defaultAuthenticatedPage",
                                  IsRequired = true)]
        public string AuthenticatedUserDefaultPage
        {
            get
            {
                return (string)this["defaultAuthenticatedPage"];
            }
        }

        /// <summary>
        /// Gets the <see cref="IGatsbApplicationProvider"/> that creates and manages the <see cref="GatsbApplication"/>
        /// instances.
        /// </summary>
        [ConfigurationProperty("appProviderType",
                                  IsRequired = true)]
        public string AppProviderTypeName
        {
            get
            {
                return (string)this["appProviderType"];
            }
        }

        /// <summary>
        /// Gets the name of the SMTP server to send outgoing mail.
        /// </summary>
        [ConfigurationProperty("smtpServer",
                          IsRequired = true)]
        public string SmtpServer
        {
            get
            {
                return (string)this["smtpServer"];
            }
        }

        /// <summary>
        /// Gets the connection string used to connect to the Gatsb database.
        /// </summary>
        [ConfigurationProperty("sqlConnectionString",
                                  IsRequired = true)]
        public string SqlConnectionString
        {
            get
            {
                return (string)this["sqlConnectionString"];
            }
        }
    }
}
